Practical D3.js by Tarek Amr & Rayna Stamboliyska

Practical D3.js by Tarek Amr & Rayna Stamboliyska

Author:Tarek Amr & Rayna Stamboliyska
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA


Check Figure 5-3 to see how the labels might look like here.

Figure 5-3.Comparing Brazil’s and Italy’s GDP

When to Use D3

Using SVG tags is easy when you are dealing with simple charts. However, suppose someone asked you to represent the GDPs of the top 20, 50, or 200 economies instead of just four. If you used the previous method, you would have to write 200 lines for 200 rect tags, each with the same x position, height and colors. And then you’d have to do the same for the 200 text labels. And then, just when you’re finished, your client asks you to change the color of the bars from blue to red. That means you have edit the 200 lines of code you just wrote. And what if your client wants a thinner or thicker border? Or what if the client now wants to show only a fraction of the GDPs within the same drawing area? And what if the GDP of those economies differs only minimally, which means the scale you introduced before, based on the top four economies, no longer yields a noticeable difference (see Figure 5-3)? Would you start resizing your canvas and the dimensions of the bars? Clearly, coding charts by hand using SVG has its limitations: it makes it extremely difficult to modify charts dynamically because you cannot easily separate the data from the logical decisions you’ve made up front.

In conclusion, the D3 JavaScript library is designed to help decouple the data and the logic needed to represent the data, hence its name Data-Driven Documents (D3) . D3 also offers you many additional capabilities. Throughout the remaining chapters of this book you will learn about the library’s other capabilities, such as scales, layouts, animations, data handling, and so on.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.